home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / remove_file.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  2KB  |  79 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: remove_file.c,v 1.33 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #include <string.h>
  8. #include "opennap.h"
  9. #include "debug.h"
  10.  
  11. #ifndef ROUTING_ONLY
  12.  
  13. /* 102 <filename> */
  14. HANDLER (remove_file)
  15. {
  16.     USER   *user;
  17.     DATUM  *info;
  18.     unsigned int fsize;
  19.     char *arg;
  20.  
  21.     (void) tag;
  22.     (void) len;
  23.     ASSERT (validate_connection (con));
  24.     CHECK_USER_CLASS ("remove_file");
  25.     user = con->user;
  26.     if (!user->shared)
  27.     {
  28.     send_cmd (con, MSG_SERVER_NOSUCH, "Not sharing any files");
  29.     return;
  30.     }
  31.  
  32.     arg = next_arg (&pkt);
  33.     if (!arg)
  34.     {
  35.     send_cmd (con, MSG_SERVER_NOSUCH, "remove file failed: missing argument");
  36.     return;
  37.     }
  38.  
  39.     /* find the file in the user's list */
  40.     info = hash_lookup (con->uopt->files, arg);
  41.     if (!info)
  42.     {
  43.     send_cmd (con, MSG_SERVER_NOSUCH, "Not sharing that file");
  44.     return;
  45.     }
  46.  
  47.     /* adjust the global state information */
  48.     fsize = info->size / 1024;    /* kB */
  49.  
  50.     if (fsize > user->libsize)
  51.     {
  52.     log ("remove_file: bad lib size for %s, fsize=%u user->libsize=%u",
  53.          user->nick, fsize, user->libsize);
  54.     user->libsize = fsize;    /* prevent negative count */
  55.     }
  56.     user->libsize -= fsize;
  57.  
  58.     if (fsize > Num_Gigs)
  59.     {
  60.     log ("remove_file: bad lib size for %s, fsize=%u Num_Gigs=%f",
  61.          user->nick, fsize, Num_Gigs);
  62.     Num_Gigs = fsize;    /* prevent negative count */
  63.     }
  64.     Num_Gigs -= fsize;
  65.  
  66.     ASSERT (Num_Files > 0);
  67.     Num_Files--;
  68.  
  69.     ASSERT (Local_Files > 0);
  70.     Local_Files--;
  71.  
  72.     user->shared--;
  73.     user->unsharing = 1;    /* note that we are unsharing */
  74.  
  75.     /* this invokes free_datum() indirectly */
  76.     hash_remove (con->uopt->files, info->filename);
  77. }
  78. #endif /* ! ROUTING_ONLY */
  79.